Repository navigation
fix(json): a truncated or malformed escape is an encoding error - #7
Merged
Merged
Conversation
fgetxattr was not retried on EINTR, so a signal refused the replacement. atomicWrite also leaked the temporary path, the step names and the spare ACL read. Tests cover both under std.testing.allocator.
copyTo renames the new bytes into place, so a full disk or a file-size limit leaves an existing file unchanged. appendLine rolls a short write back to the size before it, so the line list does not gain a partial line.
lockExclusive reads its deadline from the monotonic clock, so a signal that cuts a sleep short does not expire the wait. RootLock refuses a gate or sidecar that is not a regular file of this user with one link.
decodeCache and key comparison read past a string that ended on a backslash. They now return an encoding error, and the bytes allocated before that error are freed.
The list was abandoned on the error path, and the slice it returned was not the whole allocation, so a caller could not free it.
The archive is written under a temporary name, synced and renamed. A crash or a short write no longer leaves a partial name.gz that a later run skips.
groupAlive treated EINTR from getdents as "nobody is alive", so waitGroupGone could return while the group was still running.
COMPAT.md said errno 134 was the unnamed hardware-error text. On x86_64 that text is errno 133, HWPOISON, which Zig names; 134 is unnamed, as glibc prints it. The module summary matches the copy and the lock gate.
A caller started with fd 0, 1 or 2 closed gets /dev/null at that number. With fd 1 closed the child's stderr ends up in the captured stdout; with fd 0 or 2 closed the child loses that stream at exec. Each test forks, closes the descriptor and checks what the child sees. They fail until childExec is fixed.
…reams When the caller started with fd 0, 1 or 2 closed, /dev/null or a pipe took that number, and childExec's dup2 sequence either clobbered it (fd 1: the child's stderr went to the captured stdout) or made a no-op dup2 onto itself that kept close-on-exec (fd 0 or 2: the child started with that stream closed). Sources below 3 now move above 2 before the dup2s, as Python's _posixsubprocess does.
With SIGCHLD set to SIG_IGN the kernel reaps the child itself and wait4 fails with ECHILD. reap reports that as a kill by signal 9, so a child that exited 3 reads as SIGKILLed. The test expects error.NoChild and fails until reap returns the wait4 error.
reap turned any wait4 failure into a kill by signal 9. With SIGCHLD ignored the kernel reaps the child and wait4 fails with ECHILD, so run reported a SIGKILL for a child that exited normally. reap now returns the wait4 error through sys.call, run returns error.NoChild with sys.last_errno set, and run's doc says not to ignore SIGCHLD. The error paths still reap and keep their own error.
decodeCache("abc\\") and decodeWire("\\u12") index past the string and
panic, as does a key lookup on a key that ends in a backslash. The
decoders also take "\\u+123" (parseInt allows a sign) and read
"\\x0041" as a \u escape. The test expects error.Encoding under
std.testing.allocator, so nothing allocated before the error may leak.
codePoints read raw[i + 1] and the four \u digits without a bounds check, so a string ending in a backslash or a short \u escape panicked. It also handed any unknown escape to the \u branch and parsed the digits with parseInt, which accepts a sign. Escapes are now checked: a cut-off, unknown or non-hex escape is error.Encoding. keyEql gets the same bounds check. The decoders free their scratch and partial output on error, and return exact-length slices.
HaoZeke
force-pushed
the
fix/json-escapes
branch
from
November 16, 2026 08:16
c41b205 to
fe15bec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A truncated or malformed escape is now
error.Encoding, and what was allocated before the error is freed.codePointsreadraw[i + 1]and the four\udigits without a bounds check, so a string ending in a backslash or a short\uescape panicked. It also handed any unknown escape to the\ubranch and parsed the digits withparseInt, which accepts a sign.error.Encoding.keyEqlgets the same bounds check. The decoders free their scratch and partial output on error, and return exact-length slices.decodeCache,decodeWire, a key that ends in a backslash, a signed\uform and a non-\uescape, understd.testing.allocator.Conflicts with #3 (fix/safety) in
src/json.zig; whichever lands second needs a rebase.The branch has a CHANGELOG Unreleased entry.